package com.diaohaiwen.framework.openapi.interceptor;

import com.diaohaiwen.common.obj.cache.RequestCache;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;

import java.util.List;
import java.util.Map;

/**
 * @author 刁海文
 * @since 2023/6/15 21:31
 * @Remark
 */
public class FeignHeaderInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {

        MultiValueMap<String, String> headers = RequestCache.headers();

        // 添加请求头
        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
            requestTemplate.header(entry.getKey(), entry.getValue());
        }
    }
}
